<?php

	// TITLE: Labor AUTO MODEL
	// FILE: scaffolding/model/labor.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createLabor = function($con, $labor) {
		$sql = 'INSERT INTO labor (donation_id, method, project_id, amount) VALUES (';
		$sql .= $labor->getDonationId() . ', ';
		$sql .= $labor->getMethod() . ', ';
		$sql .= $labor->getProjectId() . ', ';
		$sql .= $labor->getAmount() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readLabor = function($con, $id) {
		$sql = 'SELECT * FROM labor WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$labor = new Labor();
			$labor->setDonationId($dbio->select($readDonation(result[0])));
			$labor->setMethod(result[1]);
			$labor->setProjectId($dbio->select($readProject(result[2])));
			$labor->setAmount(result[3]);
		} else {
			$labor = false;
		}
		return $labor;
	};

	$updateLabor = function($con, $labor) {
		$sql = 'UPDATE labor SET ';
		$sql .= 'donation_id = ' . $labor->getDonationId() . ', ';
		$sql .= 'method = ' . $labor->getMethod() . ', ';
		$sql .= 'project_id = ' . $labor->getProjectId() . ', ';
		$sql .= 'amount = ' . $labor->getAmount() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteLabor = function($con, $id) {
		$sql = 'DELETE FROM labor WHERE donation_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listLabor = function($con) {
		$sql = 'SELECT * FROM labor';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$labors = array();
			while ($result = mysqli_fetch_array($results)) {
				$labor = new Labor();
				$labor->setDonationId($dbio->select($readDonation(result[0])));
				$labor->setMethod(result[1]);
				$labor->setProjectId($dbio->select($readProject(result[2])));
				$labor->setAmount(result[3]);
				$labors[] = labor;
			}// end while
		} else {
			$labors = false;
		}
		return $labors;
	};

